/*
* Author:JacksonCoder
* CreateTime:
* Version: 1.0.0
*/

fn main() {
    loop {
        println!("无限循环！");
        break; // 退出
    }

    let mut counter = 0;
    loop {
        counter += 1;

        if counter == 10 {
            break;
        }
        println!("计数器达到: {}", counter);
    }

    let mut n = 0;

    let ret = loop {
        n += 1;

        if n == 10 {
            break n * 2;
        }
    };
    println!("结果: {}", ret); // 输出 20

    let mut a = 0;
    loop {
        a += 2;
        if a == 8 {
            continue;
        }

        if a == 20 {
            break;
        }
    }
    print!("a 最后的值为{}\n", a);

    let mut number = 3;
    while number != 0 {
        println!("{}!", number);
        number -= 1;
    }

    print!("shoot !!! \n");

    let arr = [10, 20, 30, 40, 50];
    let mut index = 0;

    while index < arr.len() {
        println!("idx {} - 值: {}", index, arr[index]);
        index += 1;
    }

    for u in (1..6).rev() {
        // 3, 2, 1（rev() 反转）
        println!("{}!", u);
    }
    println!("发射");

    let a = [10, 20, 30];

    for (index, value) in a.iter().enumerate() {
        println!("索引 {} 的值: {}", index, value);
    }

    let mut count = 0;
    'counting_up: loop {
        println!("count = {}", count);
        let mut remaining = 10;

        loop {
            println!("remaining = {} ", remaining);
            if remaining == 9 {
                break; // 退出内层循环
            }

            if count == 2 {
                break 'counting_up; // 退出外层
            }
            remaining -= 1;
        }

        count += 1;
    }
    println!("结束 count = {} ",count);
}
